load(
    "@io_bazel_rules_go//go/private:tools/lines_sorted_test.bzl",
    "lines_sorted_test",
)
load(
    "@io_bazel_rules_go//go/private:rules/nogo.bzl",
    "nogo",
)
load(
    "@io_bazel_rules_go//go/private:rules/info.bzl",
    "go_info",
)
load(
    "@io_bazel_rules_go//go:def.bzl",
    "TOOLS_NOGO",
)
load(
    "@io_bazel_rules_go//go/private:context.bzl",
    "cgo_context_data",
    "cgo_context_data_proxy",
    "go_config",
    "go_context_data",
)
load(
    "@io_bazel_rules_go//go/private:rules/stdlib.bzl",
    "stdlib",
)

stdlib(
    name = "stdlib",
    cgo_context_data = select({
        "//go/platform:internal_cgo_off": None,
        "//conditions:default": ":cgo_context_data",
    }),
    visibility = ["//visibility:public"],
)

# default_nogo is the nogo target that nogo references by default. It
# does not analyze anything, which means no binary is built or run
# at compile time.
nogo(
    name = "default_nogo",
    visibility = ["//visibility:public"],
)

# tools_nogo includes all of the analysis passes in
# golang.org/x/tools/go/analysis/passes.
# This is not backward compatible, so use caution when depending on this --
# new analyses may discover issues in existing builds.
nogo(
    name = "tools_nogo",
    visibility = ["//visibility:public"],
    deps = TOOLS_NOGO,
)

# go_context_data collects build options and is depended on by all Go targets.
# It may depend on cgo_context_data if CGo isn't disabled.
go_context_data(
    name = "go_context_data",
    cgo_context_data = select({
        "//go/platform:internal_cgo_off": None,
        "//conditions:default": ":cgo_context_data",
    }),
    coverdata = "//go/tools/coverdata",
    go_config = ":go_config",
    nogo = "@io_bazel_rules_nogo//:nogo",
    stdlib = ":stdlib",
    visibility = ["//visibility:public"],
)

# cgo_context_data collects information about the C/C++ toolchain.
# go_context_data depends if cgo is enabled in the target configuration.
cgo_context_data(
    name = "cgo_context_data",
    visibility = ["//visibility:private"],
)

# cgo_context_data_proxy depends on cgo_context_data if cgo is enabled and
# forwards its provider. Rule attributes may depend on this, since they cannot
# use select.
cgo_context_data_proxy(
    name = "cgo_context_data_proxy",
    actual = select({
        "//go/platform:internal_cgo_off": None,
        "//conditions:default": ":cgo_context_data",
    }),
    visibility = ["//visibility:public"],
)

# go_config collects information about build settings in the current
# configuration. go_context_data depends on this so that rules don't need
# to depend on all build settings directly.
go_config(
    name = "go_config",
    debug = "//go/config:debug",
    gotags = "//go/config:tags",
    linkmode = "//go/config:linkmode",
    msan = "//go/config:msan",
    pure = "//go/config:pure",
    race = "//go/config:race",
    stamp = select({
        "//go/private:stamp": True,
        "//conditions:default": False,
    }),
    static = "//go/config:static",
    strip = "//go/config:strip",
    visibility = ["//visibility:public"],
)

lines_sorted_test(
    name = "contributors_sorted_test",
    size = "small",
    cmd = "grep -v '^#' $< | grep -v '^$$' >$@",
    error_message = "Contributors must be sorted by first name",
    file = "CONTRIBUTORS",
)

lines_sorted_test(
    name = "authors_sorted_test",
    size = "small",
    cmd = "grep -v '^#' $< | grep -v '^$$' >$@",
    error_message = "Authors must be sorted by first name",
    file = "AUTHORS",
)

# This could be any file, used as an anchor point for the directory in tests
exports_files(["AUTHORS"])

go_info()

filegroup(
    name = "all_files",
    testonly = True,
    srcs = [
        "BUILD.bazel",
        "WORKSPACE",
        "//extras:all_files",
        "//go:all_files",
        "//proto:all_files",
        "//third_party:all_files",
    ],
    visibility = ["//visibility:public"],
)
